/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ClientApplication.java
 *
 * Created on Aug 31, 2011, 4:05:41 PM
 */
package operator.client.gui;

import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.text.ParseException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.border.TitledBorder;
import javax.swing.text.MaskFormatter;
import operator.client.OperatorClient;
import share.ErrorException;
import share.MessageType;
import share.IPAddressFormatter;
import share.TimerLabel;

/**
 *
 * @author mire
 */
public class ClientApplication extends javax.swing.JFrame {

    /** Creates new form ClientApplication */
    public ClientApplication() {
        initComponents();

        //Center frame
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        Dimension size = this.getSize();
        screenSize.height = screenSize.height / 2;
        screenSize.width = screenSize.width / 2;
        size.height = size.height / 2;
        size.width = size.width / 2;
        int y = screenSize.height - size.height;
        int x = screenSize.width - size.width;
        this.setLocation(x, y);
    }

    private void startClient() throws ErrorException, UnknownHostException, SocketException, IOException {
        client.start();

        started = true;
        myAddressLabel.setEnabled(true);
        addressLocalLabel.setText(client.getLocalAddress());
        connectedToLabel.setEnabled(true);
        addressAndPortLabel.setText(client.getOperatorAddress() + " : " + client.getOperatorPort());
        ((TimerLabel) timerLabel).start();
        this.setTitle(client.getOperatorName() + " клијент");
        try {
            numberMask = new MaskFormatter("###/###-###");
            numberMask.setPlaceholder("_");
            prefixMask = new MaskFormatter("###");
            prefixMask.setPlaceholder("_");
        } catch (ParseException ex) {
            Logger.getLogger(ClientApplication.class.getName()).log(Level.SEVERE, null, ex);
        }
        JOptionPane.showMessageDialog(this, "Клијент подигнут!", "Успех", JOptionPane.INFORMATION_MESSAGE);
        menuButtonsEnableAll();
        setAddressMenuItem.setEnabled(true);
        setPortMenuItem.setEnabled(true);
        status = MessageType.ALIVE;
    }

    private class OnlyTxtFilter extends javax.swing.filechooser.FileFilter {

        @Override
        public boolean accept(File file) {
            // Allow only directories, or files with ".txt" extension
            return file.isDirectory() || file.getAbsolutePath().endsWith(".txt");
        }

        @Override
        public String getDescription() {
            // This description will be displayed in the dialog,
            // hard-coded = ugly, should be done via I18N
            return "Текстуални документи (*.txt)";
        }
    }

    private void menuButtonsEnableAll() {
        newUserButton.setEnabled(true);
        newUserButton.setSelected(false);
        newMultipleUsersButton.setEnabled(true);
        newMultipleUsersButton.setSelected(false);
        transferUserButton.setEnabled(true);
        transferUserButton.setSelected(false);
        transferMultipleUsersButton.setEnabled(true);
        transferMultipleUsersButton.setSelected(false);
        readLogButton.setEnabled(true);
        readLogButton.setSelected(false);
        deleteUserButton.setEnabled(true);
        deleteUserButton.setSelected(false);
    }

    private void menuButtonsDisableAll() {
        newUserButton.setEnabled(false);
        newUserButton.setSelected(false);
        newMultipleUsersButton.setEnabled(false);
        newMultipleUsersButton.setSelected(false);
        transferUserButton.setEnabled(false);
        transferUserButton.setSelected(false);
        transferMultipleUsersButton.setEnabled(false);
        transferMultipleUsersButton.setSelected(false);
        readLogButton.setEnabled(false);
        readLogButton.setSelected(false);
        deleteUserButton.setEnabled(false);
        deleteUserButton.setSelected(false);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        fileChooser = new javax.swing.JFileChooser();
        authorDialog = new javax.swing.JDialog();
        authorAvatarLabel = new javax.swing.JLabel();
        authorNameLabel = new javax.swing.JLabel();
        authorIndexLabel = new javax.swing.JLabel();
        authorMailLabel = new javax.swing.JLabel();
        newUserButton = new javax.swing.JToggleButton();
        newMultipleUsersButton = new javax.swing.JToggleButton();
        transferUserButton = new javax.swing.JToggleButton();
        transferMultipleUsersButton = new javax.swing.JToggleButton();
        readLogButton = new javax.swing.JToggleButton();
        deleteUserButton = new javax.swing.JToggleButton();
        connectedToLabel = new javax.swing.JLabel();
        addressAndPortLabel = new javax.swing.JLabel();
        mainPanel = new javax.swing.JLayeredPane();
        newUserPanel = new javax.swing.JPanel();
        defaultPanel = new javax.swing.JPanel();
        defaultPanelLabel = new javax.swing.JLabel();
        newMultipleUsersPanel = new javax.swing.JPanel();
        newMultipleUsersButtonCancel = new javax.swing.JButton();
        newMultipleUsersButtonOK = new javax.swing.JButton();
        newMultipleUsersNoLabel = new javax.swing.JLabel();
        newMultipleUsersNoTextField = new javax.swing.JFormattedTextField();
        transferUserPanel = new javax.swing.JPanel();
        transferUserOperatorNameLabel = new javax.swing.JLabel();
        transferUserOperatorNameTextField = new javax.swing.JFormattedTextField();
        transferUserButtonCancel = new javax.swing.JButton();
        transferUserButtonOK = new javax.swing.JButton();
        transferUserNumberTextField = new javax.swing.JFormattedTextField(numberMask);
        transferUserNumberLabel = new javax.swing.JLabel();
        transferUserIDTextField = new javax.swing.JFormattedTextField();
        transferUserIDLabel = new javax.swing.JLabel();
        transferMultipleUsersPanel = new javax.swing.JPanel();
        transferMultipleUsersButtonCancel = new javax.swing.JButton();
        transferMultipleUsersButtonOK = new javax.swing.JButton();
        transferMultipleUsersOperatorNameLabel = new javax.swing.JLabel();
        transferMultipleUsersOperatorNameTextField = new javax.swing.JFormattedTextField();
        transferMultipleUsersLabel = new javax.swing.JLabel();
        transferMultipleUsersTextField = new javax.swing.JFormattedTextField();
        transferMultipleUsersBrowse = new javax.swing.JButton();
        logPanel = new javax.swing.JPanel();
        logButtonOK = new javax.swing.JButton();
        logScrollPane = new javax.swing.JScrollPane();
        logScrollPaneTextArea = new javax.swing.JTextArea();
        logToolBar = new javax.swing.JToolBar();
        logToolbarSave = new javax.swing.JButton();
        logToolbarCopy = new javax.swing.JButton();
        deleteUserPanel = new javax.swing.JPanel();
        deleteUserIDLabel = new javax.swing.JLabel();
        deleteUserIDTextField = new javax.swing.JFormattedTextField();
        deleteUserButtonCancel = new javax.swing.JButton();
        deleteUserButtonOK = new javax.swing.JButton();
        deleteUserNumberLabel = new javax.swing.JLabel();
        deleteUserNumberTextField = new javax.swing.JFormattedTextField(numberMask);
        startPanel = new javax.swing.JPanel();
        startOperatorNameLabel = new javax.swing.JLabel();
        startOperatorNameTextField = new javax.swing.JFormattedTextField();
        startButtonCancel = new javax.swing.JButton();
        startButtonOK = new javax.swing.JButton();
        startOperatorAddressTextField = new javax.swing.JFormattedTextField(new IPAddressFormatter());
        startOperatorAddressLabel = new javax.swing.JLabel();
        startOperatorPortLabel = new javax.swing.JLabel();
        startOperatorPortTextField = new javax.swing.JFormattedTextField();
        timerLabel = new TimerLabel();
        myAddressLabel = new javax.swing.JLabel();
        addressLocalLabel = new javax.swing.JLabel();
        menuBar = new javax.swing.JMenuBar();
        fileMenu = new javax.swing.JMenu();
        startMenuItem = new javax.swing.JMenuItem();
        exitMenuItem = new javax.swing.JMenuItem();
        editMenu = new javax.swing.JMenu();
        setAddressMenuItem = new javax.swing.JMenuItem();
        setPortMenuItem = new javax.swing.JMenuItem();
        helpMenu = new javax.swing.JMenu();
        aboutMenuItem = new javax.swing.JMenuItem();

        fileChooser.setFileFilter(new OnlyTxtFilter());

        authorDialog.setTitle("О аутору");
        authorDialog.setMinimumSize(new java.awt.Dimension(410, 150));
        authorDialog.setResizable(false);

        authorAvatarLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/share/icons/avatar_100.png"))); // NOI18N

        authorNameLabel.setFont(new java.awt.Font("Courier New", 1, 18));
        authorNameLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        authorNameLabel.setText(" Мирко Француски");

        authorIndexLabel.setFont(new java.awt.Font("Courier New", 1, 18));
        authorIndexLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        authorIndexLabel.setText(" 225/06");

        authorMailLabel.setFont(new java.awt.Font("Courier New", 1, 18));
        authorMailLabel.setForeground(new java.awt.Color(0, 0, 255));
        authorMailLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        authorMailLabel.setText(" fm060225d@student.etf.rs");

        javax.swing.GroupLayout authorDialogLayout = new javax.swing.GroupLayout(authorDialog.getContentPane());
        authorDialog.getContentPane().setLayout(authorDialogLayout);
        authorDialogLayout.setHorizontalGroup(
            authorDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(authorDialogLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(authorAvatarLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(authorDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(authorIndexLabel)
                    .addComponent(authorMailLabel)
                    .addComponent(authorNameLabel))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        authorDialogLayout.setVerticalGroup(
            authorDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(authorDialogLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(authorDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(authorDialogLayout.createSequentialGroup()
                        .addComponent(authorNameLabel)
                        .addGap(18, 18, 18)
                        .addComponent(authorIndexLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(authorMailLabel))
                    .addComponent(authorAvatarLabel))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        authorDialog.setLocationRelativeTo(rootPane);

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Клијент");
        setResizable(false);

        newUserButton.setSelected(true);
        newUserButton.setText("Нови корисник");
        newUserButton.setEnabled(false);
        newUserButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                newUserButtonActionPerformed(evt);
            }
        });

        newMultipleUsersButton.setSelected(true);
        newMultipleUsersButton.setText("Више нових корисника");
        newMultipleUsersButton.setEnabled(false);
        newMultipleUsersButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                newMultipleUsersButtonActionPerformed(evt);
            }
        });

        transferUserButton.setSelected(true);
        transferUserButton.setText("Пренеси корисника");
        transferUserButton.setEnabled(false);
        transferUserButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                transferUserButtonActionPerformed(evt);
            }
        });

        transferMultipleUsersButton.setSelected(true);
        transferMultipleUsersButton.setText("Пренеси више корисника");
        transferMultipleUsersButton.setEnabled(false);
        transferMultipleUsersButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                transferMultipleUsersButtonActionPerformed(evt);
            }
        });

        readLogButton.setSelected(true);
        readLogButton.setText("Историја пребацивања");
        readLogButton.setEnabled(false);
        readLogButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                readLogButtonActionPerformed(evt);
            }
        });

        deleteUserButton.setSelected(true);
        deleteUserButton.setText("Обриши корисника");
        deleteUserButton.setEnabled(false);
        deleteUserButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteUserButtonActionPerformed(evt);
            }
        });

        connectedToLabel.setText("Спојен на сервер");
        connectedToLabel.setEnabled(false);

        addressAndPortLabel.setForeground(new java.awt.Color(0, 0, 255));
        addressAndPortLabel.setText(" ");

        mainPanel.setEnabled(false);
        mainPanel.setPreferredSize(new java.awt.Dimension(420, 230));

        newUserPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Додавање новог корисника", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Courier New", 1, 18), java.awt.Color.blue)); // NOI18N
        newUserPanel.setPreferredSize(new java.awt.Dimension(401, 211));
        newUserPanel.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                newUserPanelMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout newUserPanelLayout = new javax.swing.GroupLayout(newUserPanel);
        newUserPanel.setLayout(newUserPanelLayout);
        newUserPanelLayout.setHorizontalGroup(
            newUserPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 391, Short.MAX_VALUE)
        );
        newUserPanelLayout.setVerticalGroup(
            newUserPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 183, Short.MAX_VALUE)
        );

        newUserPanel.setBounds(0, 0, 401, 211);
        mainPanel.add(newUserPanel, javax.swing.JLayeredPane.DEFAULT_LAYER);
        newUserPanel.setVisible(false);

        defaultPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Courier New", 1, 18), java.awt.Color.blue)); // NOI18N
        defaultPanel.setPreferredSize(new java.awt.Dimension(401, 211));
        defaultPanel.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                defaultPanelMouseClicked(evt);
            }
        });
        defaultPanel.setLayout(new java.awt.GridBagLayout());

        defaultPanelLabel.setForeground(new java.awt.Color(0, 0, 255));
        defaultPanel.add(defaultPanelLabel, new java.awt.GridBagConstraints());

        defaultPanel.setBounds(0, 0, 401, 211);
        mainPanel.add(defaultPanel, javax.swing.JLayeredPane.DEFAULT_LAYER);
        defaultPanel.setVisible(false);

        newMultipleUsersPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Додавање више корисника", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Courier New", 1, 18), java.awt.Color.blue)); // NOI18N
        newMultipleUsersPanel.setPreferredSize(new java.awt.Dimension(401, 211));

        newMultipleUsersButtonCancel.setText("Одустани");
        newMultipleUsersButtonCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                newMultipleUsersButtonCancelActionPerformed(evt);
            }
        });

        newMultipleUsersButtonOK.setText("У реду");
        newMultipleUsersButtonOK.setMaximumSize(new java.awt.Dimension(102, 25));
        newMultipleUsersButtonOK.setMinimumSize(new java.awt.Dimension(102, 25));
        newMultipleUsersButtonOK.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                newMultipleUsersButtonOKActionPerformed(evt);
            }
        });

        newMultipleUsersNoLabel.setText("Број корисника");

        javax.swing.GroupLayout newMultipleUsersPanelLayout = new javax.swing.GroupLayout(newMultipleUsersPanel);
        newMultipleUsersPanel.setLayout(newMultipleUsersPanelLayout);
        newMultipleUsersPanelLayout.setHorizontalGroup(
            newMultipleUsersPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(newMultipleUsersPanelLayout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addComponent(newMultipleUsersNoLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 112, Short.MAX_VALUE)
                .addComponent(newMultipleUsersNoTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(28, 28, 28))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, newMultipleUsersPanelLayout.createSequentialGroup()
                .addContainerGap(176, Short.MAX_VALUE)
                .addComponent(newMultipleUsersButtonOK, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(newMultipleUsersButtonCancel)
                .addContainerGap())
        );
        newMultipleUsersPanelLayout.setVerticalGroup(
            newMultipleUsersPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, newMultipleUsersPanelLayout.createSequentialGroup()
                .addContainerGap(57, Short.MAX_VALUE)
                .addGroup(newMultipleUsersPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(newMultipleUsersNoLabel)
                    .addComponent(newMultipleUsersNoTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(50, 50, 50)
                .addGroup(newMultipleUsersPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(newMultipleUsersButtonCancel)
                    .addComponent(newMultipleUsersButtonOK, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(32, 32, 32))
        );

        newMultipleUsersPanel.setBounds(0, 0, 401, 211);
        mainPanel.add(newMultipleUsersPanel, javax.swing.JLayeredPane.DEFAULT_LAYER);
        newMultipleUsersPanel.setVisible(false);

        transferUserPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Пребацивање корисника", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Courier New", 1, 18), java.awt.Color.blue)); // NOI18N
        transferUserPanel.setMinimumSize(new java.awt.Dimension(401, 211));
        transferUserPanel.setPreferredSize(new java.awt.Dimension(401, 211));

        transferUserOperatorNameLabel.setText("Стари оператер");

        transferUserButtonCancel.setText("Одустани");
        transferUserButtonCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                transferUserButtonCancelActionPerformed(evt);
            }
        });

        transferUserButtonOK.setText("У реду");
        transferUserButtonOK.setMaximumSize(new java.awt.Dimension(102, 25));
        transferUserButtonOK.setMinimumSize(new java.awt.Dimension(102, 25));
        transferUserButtonOK.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                transferUserButtonOKActionPerformed(evt);
            }
        });

        transferUserNumberLabel.setText("Број");

        transferUserIDLabel.setText("Идентификација");

        javax.swing.GroupLayout transferUserPanelLayout = new javax.swing.GroupLayout(transferUserPanel);
        transferUserPanel.setLayout(transferUserPanelLayout);
        transferUserPanelLayout.setHorizontalGroup(
            transferUserPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(transferUserPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(transferUserPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(transferUserPanelLayout.createSequentialGroup()
                        .addGroup(transferUserPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(transferUserPanelLayout.createSequentialGroup()
                                .addComponent(transferUserIDLabel)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 114, Short.MAX_VALUE)
                                .addComponent(transferUserIDTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(transferUserPanelLayout.createSequentialGroup()
                                .addComponent(transferUserNumberLabel)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 202, Short.MAX_VALUE)
                                .addComponent(transferUserNumberTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(transferUserPanelLayout.createSequentialGroup()
                                .addComponent(transferUserOperatorNameLabel)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 118, Short.MAX_VALUE)
                                .addComponent(transferUserOperatorNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(26, 26, 26))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, transferUserPanelLayout.createSequentialGroup()
                        .addComponent(transferUserButtonOK, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(transferUserButtonCancel)
                        .addContainerGap())))
        );
        transferUserPanelLayout.setVerticalGroup(
            transferUserPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(transferUserPanelLayout.createSequentialGroup()
                .addGap(33, 33, 33)
                .addGroup(transferUserPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(transferUserOperatorNameLabel)
                    .addComponent(transferUserOperatorNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(transferUserPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(transferUserIDTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(transferUserIDLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(transferUserPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(transferUserNumberTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(transferUserNumberLabel))
                .addGap(18, 18, 18)
                .addGroup(transferUserPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(transferUserButtonCancel)
                    .addComponent(transferUserButtonOK, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(26, Short.MAX_VALUE))
        );

        transferUserPanel.setBounds(0, 0, 401, 211);
        mainPanel.add(transferUserPanel, javax.swing.JLayeredPane.DEFAULT_LAYER);
        transferUserPanel.setVisible(false);

        transferMultipleUsersPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Пребацивање више корисника", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Courier New", 1, 18), java.awt.Color.blue)); // NOI18N
        transferMultipleUsersPanel.setMinimumSize(new java.awt.Dimension(401, 211));
        transferMultipleUsersPanel.setPreferredSize(new java.awt.Dimension(401, 211));

        transferMultipleUsersButtonCancel.setText("Одустани");
        transferMultipleUsersButtonCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                transferMultipleUsersButtonCancelActionPerformed(evt);
            }
        });

        transferMultipleUsersButtonOK.setText("У реду");
        transferMultipleUsersButtonOK.setMaximumSize(new java.awt.Dimension(102, 25));
        transferMultipleUsersButtonOK.setMinimumSize(new java.awt.Dimension(102, 25));
        transferMultipleUsersButtonOK.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                transferMultipleUsersButtonOKActionPerformed(evt);
            }
        });

        transferMultipleUsersOperatorNameLabel.setText("Стари оператер");

        transferMultipleUsersLabel.setText("Датотека");

        transferMultipleUsersBrowse.setIcon(new javax.swing.ImageIcon(getClass().getResource("/share/icons/directory.png"))); // NOI18N
        transferMultipleUsersBrowse.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                transferMultipleUsersBrowseActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout transferMultipleUsersPanelLayout = new javax.swing.GroupLayout(transferMultipleUsersPanel);
        transferMultipleUsersPanel.setLayout(transferMultipleUsersPanelLayout);
        transferMultipleUsersPanelLayout.setHorizontalGroup(
            transferMultipleUsersPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(transferMultipleUsersPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(transferMultipleUsersPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, transferMultipleUsersPanelLayout.createSequentialGroup()
                        .addGroup(transferMultipleUsersPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(transferMultipleUsersOperatorNameLabel)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, transferMultipleUsersPanelLayout.createSequentialGroup()
                                .addComponent(transferMultipleUsersLabel)
                                .addGap(64, 64, 64)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 29, Short.MAX_VALUE)
                        .addGroup(transferMultipleUsersPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(transferMultipleUsersPanelLayout.createSequentialGroup()
                                .addComponent(transferMultipleUsersTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 158, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(transferMultipleUsersBrowse, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(transferMultipleUsersOperatorNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap(27, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, transferMultipleUsersPanelLayout.createSequentialGroup()
                        .addComponent(transferMultipleUsersButtonOK, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(transferMultipleUsersButtonCancel)
                        .addContainerGap())))
        );
        transferMultipleUsersPanelLayout.setVerticalGroup(
            transferMultipleUsersPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(transferMultipleUsersPanelLayout.createSequentialGroup()
                .addGap(40, 40, 40)
                .addGroup(transferMultipleUsersPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(transferMultipleUsersPanelLayout.createSequentialGroup()
                        .addComponent(transferMultipleUsersOperatorNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(22, 22, 22)
                        .addGroup(transferMultipleUsersPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(transferMultipleUsersBrowse, 0, 0, Short.MAX_VALUE)
                            .addComponent(transferMultipleUsersTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(29, 29, 29)
                        .addGroup(transferMultipleUsersPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(transferMultipleUsersButtonCancel)
                            .addComponent(transferMultipleUsersButtonOK, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(transferMultipleUsersPanelLayout.createSequentialGroup()
                        .addComponent(transferMultipleUsersOperatorNameLabel)
                        .addGap(22, 22, 22)
                        .addComponent(transferMultipleUsersLabel)))
                .addGap(25, 25, 25))
        );

        transferMultipleUsersPanel.setBounds(0, 0, 401, 211);
        mainPanel.add(transferMultipleUsersPanel, javax.swing.JLayeredPane.DEFAULT_LAYER);
        transferMultipleUsersPanel.setVisible(false);

        logPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Историја преноса", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Courier New", 1, 18), java.awt.Color.blue)); // NOI18N
        logPanel.setMinimumSize(new java.awt.Dimension(401, 211));
        logPanel.setPreferredSize(new java.awt.Dimension(401, 211));

        logButtonOK.setText("У реду");
        logButtonOK.setMaximumSize(new java.awt.Dimension(102, 25));
        logButtonOK.setMinimumSize(new java.awt.Dimension(102, 25));
        logButtonOK.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                logButtonOKActionPerformed(evt);
            }
        });

        logScrollPane.setBackground(new java.awt.Color(255, 255, 255));
        logScrollPane.setOpaque(false);

        logScrollPaneTextArea.setColumns(20);
        logScrollPaneTextArea.setEditable(false);
        logScrollPaneTextArea.setRows(5);
        logScrollPane.setViewportView(logScrollPaneTextArea);
        logScrollPaneTextArea.setVisible(false);

        logToolBar.setBorder(null);
        logToolBar.setFloatable(false);
        logToolBar.setRollover(true);
        logToolBar.setBorderPainted(false);

        logToolbarSave.setIcon(new javax.swing.ImageIcon(getClass().getResource("/share/icons/save.png"))); // NOI18N
        logToolbarSave.setToolTipText("Сними");
        logToolbarSave.setFocusable(false);
        logToolbarSave.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        logToolbarSave.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        logToolbarSave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                logToolbarSaveActionPerformed(evt);
            }
        });
        logToolBar.add(logToolbarSave);

        logToolbarCopy.setIcon(new javax.swing.ImageIcon(getClass().getResource("/share/icons/copy.png"))); // NOI18N
        logToolbarCopy.setToolTipText("Копирај");
        logToolbarCopy.setFocusable(false);
        logToolbarCopy.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        logToolbarCopy.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        logToolbarCopy.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                logToolbarCopyActionPerformed(evt);
            }
        });
        logToolBar.add(logToolbarCopy);

        javax.swing.GroupLayout logPanelLayout = new javax.swing.GroupLayout(logPanel);
        logPanel.setLayout(logPanelLayout);
        logPanelLayout.setHorizontalGroup(
            logPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, logPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(logPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(logScrollPane, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 367, Short.MAX_VALUE)
                    .addGroup(logPanelLayout.createSequentialGroup()
                        .addComponent(logToolBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 216, Short.MAX_VALUE)
                        .addComponent(logButtonOK, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        logPanelLayout.setVerticalGroup(
            logPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, logPanelLayout.createSequentialGroup()
                .addComponent(logScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(logPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(logButtonOK, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(logToolBar, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(22, 22, 22))
        );

        logButtonOK.setVisible(false);

        logPanel.setBounds(0, 0, 401, 211);
        mainPanel.add(logPanel, javax.swing.JLayeredPane.DEFAULT_LAYER);
        logPanel.setVisible(false);

        deleteUserPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Брисање корисника", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Courier New", 1, 18), java.awt.Color.blue)); // NOI18N
        deleteUserPanel.setPreferredSize(new java.awt.Dimension(401, 211));

        deleteUserIDLabel.setText("Идентификација");

        deleteUserButtonCancel.setText("Одустани");
        deleteUserButtonCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteUserButtonCancelActionPerformed(evt);
            }
        });

        deleteUserButtonOK.setText("У реду");
        deleteUserButtonOK.setMaximumSize(new java.awt.Dimension(102, 25));
        deleteUserButtonOK.setMinimumSize(new java.awt.Dimension(102, 25));
        deleteUserButtonOK.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteUserButtonOKActionPerformed(evt);
            }
        });

        deleteUserNumberLabel.setText("Број");

        javax.swing.GroupLayout deleteUserPanelLayout = new javax.swing.GroupLayout(deleteUserPanel);
        deleteUserPanel.setLayout(deleteUserPanelLayout);
        deleteUserPanelLayout.setHorizontalGroup(
            deleteUserPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(deleteUserPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(deleteUserPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(deleteUserPanelLayout.createSequentialGroup()
                        .addComponent(deleteUserNumberLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 191, Short.MAX_VALUE)
                        .addComponent(deleteUserNumberTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(37, 37, 37))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, deleteUserPanelLayout.createSequentialGroup()
                        .addComponent(deleteUserButtonOK, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(deleteUserButtonCancel)
                        .addContainerGap())
                    .addGroup(deleteUserPanelLayout.createSequentialGroup()
                        .addComponent(deleteUserIDLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 103, Short.MAX_VALUE)
                        .addComponent(deleteUserIDTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(37, 37, 37))))
        );
        deleteUserPanelLayout.setVerticalGroup(
            deleteUserPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(deleteUserPanelLayout.createSequentialGroup()
                .addGap(40, 40, 40)
                .addGroup(deleteUserPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(deleteUserIDTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(deleteUserIDLabel))
                .addGap(18, 18, 18)
                .addGroup(deleteUserPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(deleteUserPanelLayout.createSequentialGroup()
                        .addComponent(deleteUserNumberTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(27, 27, 27)
                        .addGroup(deleteUserPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(deleteUserButtonCancel)
                            .addComponent(deleteUserButtonOK, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(deleteUserPanelLayout.createSequentialGroup()
                        .addGap(14, 14, 14)
                        .addComponent(deleteUserNumberLabel)))
                .addGap(183, 183, 183))
        );

        deleteUserPanel.setBounds(0, 0, 401, 211);
        mainPanel.add(deleteUserPanel, javax.swing.JLayeredPane.DEFAULT_LAYER);
        deleteUserPanel.setVisible(false);

        startPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Покретање клијента", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Courier New", 1, 18), java.awt.Color.blue)); // NOI18N
        startPanel.setMinimumSize(new java.awt.Dimension(401, 211));
        startPanel.setPreferredSize(new java.awt.Dimension(401, 211));

        startOperatorNameLabel.setText("Оператер");

        startButtonCancel.setText("Одустани");
        startButtonCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                startButtonCancelActionPerformed(evt);
            }
        });

        startButtonOK.setText("У реду");
        startButtonOK.setMaximumSize(new java.awt.Dimension(102, 25));
        startButtonOK.setMinimumSize(new java.awt.Dimension(102, 25));
        startButtonOK.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                startButtonOKActionPerformed(evt);
            }
        });

        startOperatorAddressLabel.setText("Адреса");

        startOperatorPortLabel.setText("Порт");

        javax.swing.GroupLayout startPanelLayout = new javax.swing.GroupLayout(startPanel);
        startPanel.setLayout(startPanelLayout);
        startPanelLayout.setHorizontalGroup(
            startPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(startPanelLayout.createSequentialGroup()
                .addGroup(startPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(startPanelLayout.createSequentialGroup()
                        .addGap(176, 176, 176)
                        .addComponent(startButtonOK, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(startButtonCancel))
                    .addGroup(startPanelLayout.createSequentialGroup()
                        .addGap(38, 38, 38)
                        .addGroup(startPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(startOperatorNameLabel)
                            .addComponent(startOperatorAddressLabel)
                            .addComponent(startOperatorPortLabel))
                        .addGap(126, 126, 126)
                        .addGroup(startPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(startOperatorAddressTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(startOperatorNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(startOperatorPortTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        startPanelLayout.setVerticalGroup(
            startPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(startPanelLayout.createSequentialGroup()
                .addGap(27, 27, 27)
                .addGroup(startPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(startPanelLayout.createSequentialGroup()
                        .addComponent(startOperatorNameLabel)
                        .addGap(18, 18, 18)
                        .addComponent(startOperatorAddressLabel)
                        .addGap(18, 18, 18)
                        .addComponent(startOperatorPortLabel)
                        .addContainerGap())
                    .addGroup(startPanelLayout.createSequentialGroup()
                        .addComponent(startOperatorNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(startOperatorAddressTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(startOperatorPortTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 28, Short.MAX_VALUE)
                        .addGroup(startPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(startButtonCancel)
                            .addComponent(startButtonOK, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(22, 22, 22))))
        );

        startPanel.setBounds(0, 0, 401, 211);
        mainPanel.add(startPanel, javax.swing.JLayeredPane.DEFAULT_LAYER);
        startPanel.setVisible(false);

        timerLabel.setText("00:00:00");

        myAddressLabel.setText("Моја адреса");
        myAddressLabel.setEnabled(false);

        addressLocalLabel.setForeground(new java.awt.Color(0, 0, 255));
        addressLocalLabel.setText(" ");

        fileMenu.setMnemonic('f');
        fileMenu.setText("Мени");

        startMenuItem.setMnemonic('o');
        startMenuItem.setText("Старт");
        startMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                startMenuItemActionPerformed(evt);
            }
        });
        fileMenu.add(startMenuItem);

        exitMenuItem.setMnemonic('x');
        exitMenuItem.setText("Излаз");
        exitMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exitMenuItemActionPerformed(evt);
            }
        });
        fileMenu.add(exitMenuItem);

        menuBar.add(fileMenu);

        editMenu.setMnemonic('e');
        editMenu.setText("Промени");

        setAddressMenuItem.setText("Адресу сервера");
        setAddressMenuItem.setEnabled(false);
        setAddressMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                setAddressMenuItemActionPerformed(evt);
            }
        });
        editMenu.add(setAddressMenuItem);

        setPortMenuItem.setText("Порт");
        setPortMenuItem.setEnabled(false);
        setPortMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                setPortMenuItemActionPerformed(evt);
            }
        });
        editMenu.add(setPortMenuItem);

        menuBar.add(editMenu);

        helpMenu.setMnemonic('h');
        helpMenu.setText("Помоћ");

        aboutMenuItem.setMnemonic('a');
        aboutMenuItem.setText("Аутор");
        aboutMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                aboutMenuItemActionPerformed(evt);
            }
        });
        helpMenu.add(aboutMenuItem);

        menuBar.add(helpMenu);

        setJMenuBar(menuBar);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(newUserButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(transferMultipleUsersButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(transferUserButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(newMultipleUsersButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(readLogButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(deleteUserButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(myAddressLabel)
                        .addGap(17, 17, 17)
                        .addComponent(addressLocalLabel)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(connectedToLabel)
                        .addGap(29, 29, 29)
                        .addComponent(addressAndPortLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 198, Short.MAX_VALUE)
                        .addComponent(timerLabel))
                    .addComponent(mainPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 412, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(timerLabel)
                        .addComponent(connectedToLabel)
                        .addComponent(addressAndPortLabel))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(myAddressLabel)
                        .addComponent(addressLocalLabel)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 27, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(newUserButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(newMultipleUsersButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(transferUserButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(transferMultipleUsersButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(readLogButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(deleteUserButton))
                    .addComponent(mainPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 230, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitMenuItemActionPerformed
        System.exit(0);
    }//GEN-LAST:event_exitMenuItemActionPerformed

private void startMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_startMenuItemActionPerformed
    if (OperatorClient.existsConfugration()) {
        boolean error = false;
        client = new OperatorClient();
        try {
            startClient();
        } catch (ErrorException ex) {
            JOptionPane.showMessageDialog(this, ex.toString(), "Грешка", JOptionPane.ERROR_MESSAGE);
            error = true;
        } catch (UnknownHostException ex) {
            JOptionPane.showMessageDialog(this, ex.toString(), "Грешка", JOptionPane.ERROR_MESSAGE);
            error = true;
        } catch (SocketException ex) {
            JOptionPane.showMessageDialog(this, ex.toString(), "Грешка", JOptionPane.ERROR_MESSAGE);
            error = true;
        } catch (IOException ex) {
            JOptionPane.showMessageDialog(this, ex.toString(), "Грешка", JOptionPane.ERROR_MESSAGE);
            error = true;
        }
        if (!error) {
            mainPanel.setEnabled(true);
            startMenuItem.setEnabled(false);
        }
    } else {
        defaultPanel.setVisible(false);
        startPanel.setVisible(true);
    }
}//GEN-LAST:event_startMenuItemActionPerformed

private void startButtonCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_startButtonCancelActionPerformed
    startPanel.setVisible(false);
    TitledBorder defaultBorder = ((TitledBorder) defaultPanel.getBorder());
    defaultBorder.setTitle("");
    defaultPanel.setVisible(true);
    defaultPanel.repaint();
    startOperatorNameTextField.setText(null);
    startOperatorAddressTextField.setText(null);
    startOperatorPortTextField.setText(null);
}//GEN-LAST:event_startButtonCancelActionPerformed

private void startButtonOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_startButtonOKActionPerformed
    startPanel.setVisible(false);
    status = MessageType.NEW_CLIENT;
    defaultPanel.setVisible(true);
    String operatorName = startOperatorNameTextField.getText();
    String operatorAddress = startOperatorAddressTextField.getText();
    String operatorPortString = startOperatorPortTextField.getText();

    if (operatorName == null || operatorName.equals("")
            || operatorAddress == null || operatorAddress.equals("")
            || operatorPortString == null || operatorPortString.equals("")) {
        JOptionPane.showMessageDialog(this, "Нису унети сви параметри", "Грешка", JOptionPane.ERROR_MESSAGE);
        startPanel.setVisible(true);
        defaultPanel.setVisible(false);
        return;
    }

    int operatorPort = 0;
    try {
        operatorPort = Integer.parseInt(operatorPortString);
    } catch (NumberFormatException ex) {
        JOptionPane.showMessageDialog(this, "Погрешно унети параметри", "Грешка", JOptionPane.ERROR_MESSAGE);
        transferUserPanel.setVisible(true);
        return;
    }
    if (operatorPort <= 0) {
        JOptionPane.showMessageDialog(this, "Не можете унети 0", "Грешка", JOptionPane.ERROR_MESSAGE);
        transferUserPanel.setVisible(true);
        return;
    }
    boolean error = false;
    client = new OperatorClient(operatorAddress, operatorPort, operatorName);
    try {
        startClient();
    } catch (ErrorException ex) {
        JOptionPane.showMessageDialog(this, ex.toString(), "Грешка", JOptionPane.ERROR_MESSAGE);
        error = true;
    } catch (UnknownHostException ex) {
        JOptionPane.showMessageDialog(this, ex.toString(), "Грешка", JOptionPane.ERROR_MESSAGE);
        error = true;
    } catch (SocketException ex) {
        JOptionPane.showMessageDialog(this, ex.toString(), "Грешка", JOptionPane.ERROR_MESSAGE);
        error = true;
    } catch (IOException ex) {
        JOptionPane.showMessageDialog(this, ex.toString(), "Грешка", JOptionPane.ERROR_MESSAGE);
        error = true;
    }
    if (!error) {
        mainPanel.setEnabled(true);
        startMenuItem.setEnabled(false);
    }
}//GEN-LAST:event_startButtonOKActionPerformed

private void newMultipleUsersButtonCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newMultipleUsersButtonCancelActionPerformed
    newMultipleUsersPanel.setVisible(false);
    newMultipleUsersNoTextField.setText(null);
    defaultPanel.setVisible(true);
    menuButtonsEnableAll();
}//GEN-LAST:event_newMultipleUsersButtonCancelActionPerformed

private void newMultipleUsersButtonOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newMultipleUsersButtonOKActionPerformed
    status = MessageType.NEW_MULTIPLE_USERS;
    newMultipleUsersPanel.setVisible(false);
    String number = newMultipleUsersNoTextField.getText();

    if (number == null || number.equals("")) {
        JOptionPane.showMessageDialog(this, "Нису унети сви параметри", "Грешка", JOptionPane.ERROR_MESSAGE);
        newMultipleUsersPanel.setVisible(true);
        return;
    }
    int usersNo = 0;
    try {
        usersNo = Integer.parseInt(number);
    } catch (NumberFormatException ex) {
        JOptionPane.showMessageDialog(this, "Погрешно унети параметри", "Грешка", JOptionPane.ERROR_MESSAGE);
        newMultipleUsersPanel.setVisible(true);
        return;
    }
    if (usersNo <= 0) {
        if (usersNo == 0) {
            JOptionPane.showMessageDialog(this, "Не можете унети 0", "Грешка", JOptionPane.ERROR_MESSAGE);
        } else {
            JOptionPane.showMessageDialog(this, "Не можете унети негативан број", "Грешка", JOptionPane.ERROR_MESSAGE);
        }
        newMultipleUsersPanel.setVisible(true);
        return;
    }

    TitledBorder logBorder = ((TitledBorder) logPanel.getBorder());
    logBorder.setTitle(((TitledBorder) newMultipleUsersPanel.getBorder()).getTitle());
    logPanel.repaint();
    logPanel.setVisible(true);

    String usersIDs = null;
    try {
        usersIDs = client.newMultipleUsers(usersNo);
    } catch (ErrorException ex) {
        JOptionPane.showMessageDialog(this, ex.toString(), "Грешка", JOptionPane.ERROR_MESSAGE);
    } catch (SocketException ex) {
        JOptionPane.showMessageDialog(this, ex.toString(), "Грешка", JOptionPane.ERROR_MESSAGE);
    } catch (IOException ex) {
        JOptionPane.showMessageDialog(this, ex.toString(), "Грешка", JOptionPane.ERROR_MESSAGE);
    } catch (OutOfMemoryError err) {
        JOptionPane.showMessageDialog(this, err.toString(), "Грешка", JOptionPane.ERROR_MESSAGE);
    }
    if (usersIDs != null) {
        logScrollPaneTextArea.setText(usersIDs);
        logScrollPaneTextArea.setVisible(true);
        logButtonOK.setVisible(true);
    } else {
        logButtonOKActionPerformed(evt);
    }
}//GEN-LAST:event_newMultipleUsersButtonOKActionPerformed

private void transferUserButtonCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_transferUserButtonCancelActionPerformed
    transferUserPanel.setVisible(false);
    transferUserOperatorNameTextField.setText(null);
    transferUserIDTextField.setText(null);
    transferUserNumberTextField.setText(null);
    defaultPanel.setVisible(true);
    menuButtonsEnableAll();
}//GEN-LAST:event_transferUserButtonCancelActionPerformed

private void transferUserButtonOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_transferUserButtonOKActionPerformed
    status = MessageType.TRANSFER;
    transferUserPanel.setVisible(false);
    defaultPanel.setVisible(true);

    String operatorName = transferUserOperatorNameTextField.getText();
    String userIDString = transferUserIDTextField.getText();
    String userNumber = transferUserNumberTextField.getText();

    if (operatorName == null || operatorName.equals("")
            || userIDString == null || userIDString.equals("")
            || userNumber == null || userNumber.equals("")) {
        JOptionPane.showMessageDialog(this, "Нису унети сви параметри", "Грешка", JOptionPane.ERROR_MESSAGE);
        transferUserPanel.setVisible(true);
        return;
    }
    int userId = 0;
    try {
        userId = Integer.parseInt(userIDString);
    } catch (NumberFormatException ex) {
        JOptionPane.showMessageDialog(this, "Погрешно унети параметри", "Грешка", JOptionPane.ERROR_MESSAGE);
        transferUserPanel.setVisible(true);
        return;
    }
    if (userId == 0) {
        JOptionPane.showMessageDialog(this, "Не можете унети 0", "Грешка", JOptionPane.ERROR_MESSAGE);
        transferUserPanel.setVisible(true);
        return;
    }
    transferUserOperatorNameTextField.setText(null);
    transferUserIDTextField.setText(null);
    transferUserNumberTextField.setText(null);
    boolean success = false;
    try {
        success = client.transfer(operatorName, userId, userNumber);
    } catch (ErrorException ex) {
        JOptionPane.showMessageDialog(this, ex.toString(), "Грешка", JOptionPane.ERROR_MESSAGE);
    } catch (SocketException ex) {
        JOptionPane.showMessageDialog(this, ex.toString(), "Грешка", JOptionPane.ERROR_MESSAGE);
    } catch (IOException ex) {
        JOptionPane.showMessageDialog(this, ex.toString(), "Грешка", JOptionPane.ERROR_MESSAGE);
    }
    if (success) {
        JOptionPane.showMessageDialog(this, "Посао послат!", "Успех", JOptionPane.INFORMATION_MESSAGE);
    }
    menuButtonsEnableAll();
}//GEN-LAST:event_transferUserButtonOKActionPerformed

private void deleteUserButtonCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteUserButtonCancelActionPerformed
    deleteUserPanel.setVisible(false);
    deleteUserIDTextField.setText(null);
    deleteUserNumberTextField.setText(null);
    defaultPanel.setVisible(true);
    menuButtonsEnableAll();
}//GEN-LAST:event_deleteUserButtonCancelActionPerformed

private void deleteUserButtonOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteUserButtonOKActionPerformed
    status = MessageType.DELETE_USER;

    deleteUserPanel.setVisible(false);


    String userNumber = deleteUserNumberTextField.getText();
    String userIDString = deleteUserIDTextField.getText();


    if (userIDString == null || userIDString.equals("")
            || userNumber == null || userNumber.equals("")) {
        JOptionPane.showMessageDialog(this, "Нису унети сви параметри", "Грешка", JOptionPane.ERROR_MESSAGE);
        deleteUserPanel.setVisible(true);
        return;
    }

    int userID = 0;
    try {
        userID = Integer.parseInt(userIDString);
    } catch (NumberFormatException ex) {
        JOptionPane.showMessageDialog(this, "Погрешно унети параметри", "Грешка", JOptionPane.ERROR_MESSAGE);
        deleteUserPanel.setVisible(true);
        return;
    }
    if (userID == 0) {
        JOptionPane.showMessageDialog(this, "Не можете унети 0", "Грешка", JOptionPane.ERROR_MESSAGE);
        deleteUserPanel.setVisible(true);
        return;
    }

    TitledBorder defaultBorder = ((TitledBorder) defaultPanel.getBorder());
    defaultBorder.setTitle(((TitledBorder) deleteUserPanel.getBorder()).getTitle());
    defaultPanel.setVisible(true);


    deleteUserNumberTextField.setText(null);
    deleteUserIDTextField.setText(null);
    boolean success = false;
    try {
        success = client.deleteUser(userID, userNumber);
    } catch (ErrorException ex) {
        JOptionPane.showMessageDialog(this, ex.toString(), "Грешка", JOptionPane.ERROR_MESSAGE);
    } catch (SocketException ex) {
        JOptionPane.showMessageDialog(this, ex.toString(), "Грешка", JOptionPane.ERROR_MESSAGE);
    } catch (IOException ex) {
        JOptionPane.showMessageDialog(this, ex.toString(), "Грешка", JOptionPane.ERROR_MESSAGE);
    }
    if (success) {
        JOptionPane.showMessageDialog(this, "Корисник " + userID + " обрисан!", "Успех", JOptionPane.INFORMATION_MESSAGE);
    }

    menuButtonsEnableAll();
}//GEN-LAST:event_deleteUserButtonOKActionPerformed

private void transferMultipleUsersButtonCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_transferMultipleUsersButtonCancelActionPerformed
    transferMultipleUsersPanel.setVisible(false);
    transferMultipleUsersOperatorNameTextField.setText(null);
    transferMultipleUsersTextField.setText(null);
    defaultPanel.setVisible(true);
    menuButtonsEnableAll();
}//GEN-LAST:event_transferMultipleUsersButtonCancelActionPerformed

private void transferMultipleUsersButtonOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_transferMultipleUsersButtonOKActionPerformed
    status = MessageType.MULTIPLE_TRANSFER;
    transferMultipleUsersPanel.setVisible(false);
    defaultPanel.setVisible(true);

    String operatorName = transferMultipleUsersOperatorNameTextField.getText();
    String fileName = transferMultipleUsersTextField.getText();
    if (operatorName == null || operatorName.equals("")
            || fileName == null || fileName.equals("")) {
        JOptionPane.showMessageDialog(this, "Нису унети сви параметри", "Грешка", JOptionPane.ERROR_MESSAGE);
        transferMultipleUsersPanel.setVisible(true);
        defaultPanel.setVisible(false);
        return;
    }
    transferMultipleUsersOperatorNameTextField.setText(null);
    transferMultipleUsersTextField.setText(null);
    boolean success = false;
    try {
        success = client.multipleTransfer(operatorName, fileName);
    } catch (ErrorException ex) {
        JOptionPane.showMessageDialog(this, ex.toString(), "Грешка", JOptionPane.ERROR_MESSAGE);
    } catch (SocketException ex) {
        JOptionPane.showMessageDialog(this, ex.toString(), "Грешка", JOptionPane.ERROR_MESSAGE);
    } catch (IOException ex) {
        JOptionPane.showMessageDialog(this, ex.toString(), "Грешка", JOptionPane.ERROR_MESSAGE);
    } catch (OutOfMemoryError err) {
        JOptionPane.showMessageDialog(this, err.toString(), "Грешка", JOptionPane.ERROR_MESSAGE);
    }
    if (success) {
        JOptionPane.showMessageDialog(this, "Посао послат!", "Успех", JOptionPane.INFORMATION_MESSAGE);
    }
    menuButtonsEnableAll();
}//GEN-LAST:event_transferMultipleUsersButtonOKActionPerformed

private void logButtonOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_logButtonOKActionPerformed
    logPanel.setVisible(false);
    logScrollPaneTextArea.setText(null);
    logScrollPaneTextArea.setVisible(false);
    logButtonOK.setVisible(false);
    if (status != MessageType.GET_TRANSFER_LOG) {
        TitledBorder logBorder = (TitledBorder) logPanel.getBorder();
        logBorder.setTitle("Историја преноса");
        logPanel.repaint();
    }
    defaultPanel.setVisible(true);
    status = MessageType.ALIVE;
    menuButtonsEnableAll();
}//GEN-LAST:event_logButtonOKActionPerformed

private void logToolbarSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_logToolbarSaveActionPerformed
    int returnVal = fileChooser.showSaveDialog(this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        if (fileChooser.getSelectedFile() != null) {
            File theFileToSave = fileChooser.getSelectedFile();
            String text = logScrollPaneTextArea.getText();
            PrintWriter pw = null;
            try {
                pw = new PrintWriter(theFileToSave);
                pw.write(text);
            } catch (IOException ex) {
                Logger.getLogger(ClientApplication.class.getName()).log(Level.SEVERE, null, ex);
            } finally {
                if (pw != null) {
                    pw.close();
                }
            }
        }
    }
}//GEN-LAST:event_logToolbarSaveActionPerformed

private void newMultipleUsersButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newMultipleUsersButtonActionPerformed
    menuButtonsDisableAll();
    newMultipleUsersButton.setSelected(true);

    defaultPanel.setVisible(false);
    newMultipleUsersPanel.setVisible(true);
}//GEN-LAST:event_newMultipleUsersButtonActionPerformed

private void aboutMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_aboutMenuItemActionPerformed
    authorDialog.setVisible(true);
}//GEN-LAST:event_aboutMenuItemActionPerformed

private void newUserButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newUserButtonActionPerformed
    menuButtonsDisableAll();
    newUserButton.setSelected(true);
    defaultPanel.setVisible(false);

    status = MessageType.NEW_USER;
    defaultPanel.setVisible(false);
    TitledBorder logBorder = ((TitledBorder) logPanel.getBorder());
    logBorder.setTitle(((TitledBorder) newUserPanel.getBorder()).getTitle());
    logPanel.repaint();
    logPanel.setVisible(true);

    String user = null;
    try {
        user = client.newUser();
    } catch (ErrorException ex) {
        JOptionPane.showMessageDialog(this, ex.toString(), "Грешка", JOptionPane.ERROR_MESSAGE);
    } catch (SocketException ex) {
        JOptionPane.showMessageDialog(this, ex.toString(), "Грешка", JOptionPane.ERROR_MESSAGE);
    } catch (IOException ex) {
        JOptionPane.showMessageDialog(this, ex.toString(), "Грешка", JOptionPane.ERROR_MESSAGE);
    }
    if (user != null) {
        logScrollPaneTextArea.setText(user);
        logScrollPaneTextArea.setVisible(true);
        logButtonOK.setVisible(true);
    } else {
        logButtonOKActionPerformed(evt);
    }
}//GEN-LAST:event_newUserButtonActionPerformed

private void transferUserButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_transferUserButtonActionPerformed
    menuButtonsDisableAll();
    transferUserButton.setSelected(true);

    defaultPanel.setVisible(false);
    transferUserPanel.setVisible(true);
}//GEN-LAST:event_transferUserButtonActionPerformed

private void transferMultipleUsersButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_transferMultipleUsersButtonActionPerformed
    menuButtonsDisableAll();
    transferMultipleUsersButton.setSelected(true);

    defaultPanel.setVisible(false);
    transferMultipleUsersPanel.setVisible(true);
}//GEN-LAST:event_transferMultipleUsersButtonActionPerformed

private void readLogButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_readLogButtonActionPerformed
    status = MessageType.GET_TRANSFER_LOG;
    menuButtonsDisableAll();
    readLogButton.setSelected(true);

    defaultPanel.setVisible(false);
    logPanel.setVisible(true);
    String log = null;
    try {
        log = client.getTransfersLog();
    } catch (IOException ex) {
        JOptionPane.showMessageDialog(this, ex.toString(), "Грешка", JOptionPane.ERROR_MESSAGE);
    } catch (ErrorException ex) {
        if (ex.getShortErrorMessage().equals("ERROR_NO_LOG")) {
            JOptionPane.showMessageDialog(this, ex.toString(), "Грешка", JOptionPane.INFORMATION_MESSAGE);
        } else {
            JOptionPane.showMessageDialog(this, ex.toString(), "Грешка", JOptionPane.ERROR_MESSAGE);
        }
    }
    if (log == null) {
        logButtonOKActionPerformed(evt);
    } else {
        logScrollPaneTextArea.setText(log);
        logScrollPaneTextArea.setVisible(true);
        logButtonOK.setVisible(true);
        logPanel.repaint();
    }

}//GEN-LAST:event_readLogButtonActionPerformed

private void deleteUserButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteUserButtonActionPerformed
    menuButtonsDisableAll();
    deleteUserButton.setSelected(true);
    defaultPanel.setVisible(false);
    deleteUserPanel.setVisible(true);
}//GEN-LAST:event_deleteUserButtonActionPerformed

private void defaultPanelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_defaultPanelMouseClicked
    TitledBorder defaultBorder = ((TitledBorder) defaultPanel.getBorder());
    defaultBorder.setTitle(null);
    defaultPanelLabel.setText(null);
    defaultPanel.repaint();
    status = MessageType.ALIVE;
}//GEN-LAST:event_defaultPanelMouseClicked

private void transferMultipleUsersBrowseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_transferMultipleUsersBrowseActionPerformed
    int returnVal = fileChooser.showOpenDialog(this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        try {
            transferMultipleUsersTextField.setText(fileChooser.getSelectedFile().getCanonicalPath());
        } catch (IOException ex) {
            Logger.getLogger(ClientApplication.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}//GEN-LAST:event_transferMultipleUsersBrowseActionPerformed

private void logToolbarCopyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_logToolbarCopyActionPerformed
    String str = logScrollPaneTextArea.getText();
    if (str == null || str.equals("")) {
        return;
    }
    StringSelection stringSelection = new StringSelection(str);
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    clipboard.setContents(stringSelection, null);

}//GEN-LAST:event_logToolbarCopyActionPerformed

private void setAddressMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_setAddressMenuItemActionPerformed
    if (status == MessageType.ALIVE) {
        menuButtonsDisableAll();
        String address = JOptionPane.showInputDialog(rootPane, "Унесите нову адресу сервера", "Подеси адресу", JOptionPane.QUESTION_MESSAGE);
        client.setOperatorAddress(address);
        try {
            client.start();
        } catch (ErrorException ex) {
            Logger.getLogger(ClientApplication.class.getName()).log(Level.SEVERE, null, ex);
        } catch (UnknownHostException ex) {
            Logger.getLogger(ClientApplication.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(ClientApplication.class.getName()).log(Level.SEVERE, null, ex);
        }

    } else {
        JOptionPane.showMessageDialog(rootPane, "Морате сачекати да се текући захтев заврши", "Грешка", JOptionPane.ERROR_MESSAGE);
    }

}//GEN-LAST:event_setAddressMenuItemActionPerformed

private void setPortMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_setPortMenuItemActionPerformed
    if (status == MessageType.ALIVE) {
        menuButtonsDisableAll();
        String address = JOptionPane.showInputDialog(rootPane, "Унесите нови порт сервера", "Подеси порт", JOptionPane.QUESTION_MESSAGE);
        client.setOperatorPort(Integer.parseInt(address));
        try {
            client.start();
        } catch (ErrorException ex) {
            Logger.getLogger(ClientApplication.class.getName()).log(Level.SEVERE, null, ex);
        } catch (UnknownHostException ex) {
            Logger.getLogger(ClientApplication.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(ClientApplication.class.getName()).log(Level.SEVERE, null, ex);
        }

    } else {
        JOptionPane.showMessageDialog(rootPane, "Морате сачекати да се текући захтев заврши", "Грешка", JOptionPane.ERROR_MESSAGE);
    }
}//GEN-LAST:event_setPortMenuItemActionPerformed

private void newUserPanelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_newUserPanelMouseClicked
    // TODO add your handling code here:
}//GEN-LAST:event_newUserPanelMouseClicked

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new ClientApplication().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuItem aboutMenuItem;
    private javax.swing.JLabel addressAndPortLabel;
    private javax.swing.JLabel addressLocalLabel;
    private javax.swing.JLabel authorAvatarLabel;
    private javax.swing.JDialog authorDialog;
    private javax.swing.JLabel authorIndexLabel;
    private javax.swing.JLabel authorMailLabel;
    private javax.swing.JLabel authorNameLabel;
    private javax.swing.JLabel connectedToLabel;
    private javax.swing.JPanel defaultPanel;
    private javax.swing.JLabel defaultPanelLabel;
    private javax.swing.JToggleButton deleteUserButton;
    private javax.swing.JButton deleteUserButtonCancel;
    private javax.swing.JButton deleteUserButtonOK;
    private javax.swing.JLabel deleteUserIDLabel;
    private javax.swing.JFormattedTextField deleteUserIDTextField;
    private javax.swing.JLabel deleteUserNumberLabel;
    private javax.swing.JFormattedTextField deleteUserNumberTextField;
    private javax.swing.JPanel deleteUserPanel;
    private javax.swing.JMenu editMenu;
    private javax.swing.JMenuItem exitMenuItem;
    private javax.swing.JFileChooser fileChooser;
    private javax.swing.JMenu fileMenu;
    private javax.swing.JMenu helpMenu;
    private javax.swing.JButton logButtonOK;
    private javax.swing.JPanel logPanel;
    private javax.swing.JScrollPane logScrollPane;
    private javax.swing.JTextArea logScrollPaneTextArea;
    private javax.swing.JToolBar logToolBar;
    private javax.swing.JButton logToolbarCopy;
    private javax.swing.JButton logToolbarSave;
    private javax.swing.JLayeredPane mainPanel;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JLabel myAddressLabel;
    private javax.swing.JToggleButton newMultipleUsersButton;
    private javax.swing.JButton newMultipleUsersButtonCancel;
    private javax.swing.JButton newMultipleUsersButtonOK;
    private javax.swing.JLabel newMultipleUsersNoLabel;
    private javax.swing.JFormattedTextField newMultipleUsersNoTextField;
    private javax.swing.JPanel newMultipleUsersPanel;
    private javax.swing.JToggleButton newUserButton;
    private javax.swing.JPanel newUserPanel;
    private javax.swing.JToggleButton readLogButton;
    private javax.swing.JMenuItem setAddressMenuItem;
    private javax.swing.JMenuItem setPortMenuItem;
    private javax.swing.JButton startButtonCancel;
    private javax.swing.JButton startButtonOK;
    private javax.swing.JMenuItem startMenuItem;
    private javax.swing.JLabel startOperatorAddressLabel;
    private javax.swing.JFormattedTextField startOperatorAddressTextField;
    private javax.swing.JLabel startOperatorNameLabel;
    private javax.swing.JFormattedTextField startOperatorNameTextField;
    private javax.swing.JLabel startOperatorPortLabel;
    private javax.swing.JFormattedTextField startOperatorPortTextField;
    private javax.swing.JPanel startPanel;
    private javax.swing.JLabel timerLabel;
    private javax.swing.JButton transferMultipleUsersBrowse;
    private javax.swing.JToggleButton transferMultipleUsersButton;
    private javax.swing.JButton transferMultipleUsersButtonCancel;
    private javax.swing.JButton transferMultipleUsersButtonOK;
    private javax.swing.JLabel transferMultipleUsersLabel;
    private javax.swing.JLabel transferMultipleUsersOperatorNameLabel;
    private javax.swing.JFormattedTextField transferMultipleUsersOperatorNameTextField;
    private javax.swing.JPanel transferMultipleUsersPanel;
    private javax.swing.JFormattedTextField transferMultipleUsersTextField;
    private javax.swing.JToggleButton transferUserButton;
    private javax.swing.JButton transferUserButtonCancel;
    private javax.swing.JButton transferUserButtonOK;
    private javax.swing.JLabel transferUserIDLabel;
    private javax.swing.JFormattedTextField transferUserIDTextField;
    private javax.swing.JLabel transferUserNumberLabel;
    private javax.swing.JFormattedTextField transferUserNumberTextField;
    private javax.swing.JLabel transferUserOperatorNameLabel;
    private javax.swing.JFormattedTextField transferUserOperatorNameTextField;
    private javax.swing.JPanel transferUserPanel;
    // End of variables declaration//GEN-END:variables
    private OperatorClient client;
    private boolean started;
    private MessageType status = MessageType.ALIVE;
    private MaskFormatter numberMask;
    private MaskFormatter prefixMask;
}
